from django.db import models
from django import forms
from django.utils import timezone
import datetime

# Create your models here.
class Message(models.Model):
    author = models.CharField(max_length=50)
    content = models.CharField(max_length=500)
    pubDate = models.DateTimeField('date published')
    
    def __unicode__(self):
        return self.content
    
    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pubDate <  now

    was_published_recently.admin_order_field = 'pubDate'
    was_published_recently.boolean = True
    was_published_recently.short_description = 'Published recently?'
    
class ContactForm(forms.Form):
    author = forms.CharField(widget=forms.TextInput(attrs={'title':"Your Name", "id":"author", 'size':'30', 'maxlength':'50'}))
    content = forms.CharField(widget=forms.Textarea(attrs={'title':"Enter your message", "id":"content"}))
